<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ajax param</title>
<script type="text/javascript" src="${base}/script/jquery-2.0.3.min.js"></script>
<script type="text/javascript" src="${base}/script/ajaxfileupload.js"></script>
<script type="text/javascript" src="${base}/script/jquery.form.js"></script>
</head>
<body>
<input type="button" id="jsonArray" value="jsonArray" onclick="jsonArray()">
<input type="button" id="jsonString" value="jsonString" onclick="jsonString()"><br>

<hr>
<form id="frm" action="${base}/submit/formSubmit.do">
姓名：<input type="text" name="name">
年龄:<input type="text" name="age"><br>
姓名：<input type="text" name="name">
年龄:<input type="text" name="age"><br>
姓名：<input type="text" name="name">
年龄:<input type="text" name="age"><br>
type:<input type="text" name="type"><br>
<select name="select">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select><br>
radio:<input type="radio" name="radio" value="1">1<input type="radio" name="radio" value="2">2<br>
chechBox:<input type="checkbox" name="checkBox" value="1">1<input type="checkbox" name="checkBox" value="2">2<br>
<input type="submit" value="submit提交"> <input type="button" value="ajax提交" onclick="ajaxSubmit()">
</form>
<br>
<hr>

ajaxfileupload上传<input type="file" name="uploadFile" id="uploadFile">
文件名<input type="text" id="fileName" name="fileName">
<hr>

ajaxSubmit方式提交：<br>
<form id="ajaxSubmitFrm" action="${base}/submit/ajaxSubmit.do">
<input type="file" name="file">
文件名：<input type="text" name="fileName"><br>
<input type="button" value="ajaxSubmit" onclick="ajaxSub()">
</form>

<script type="text/javascript">
var arr1=[{ "id": 1, "name": "xiaoming" }, { "id": 2, "name": "xiaohong"}];
var param = {
		"type":"type",
		"students":JSON.stringify(arr1)
};

var arrayParam = {
		"type":"type",
		"students":arr1
}
//$.toJSONString(ids)
function jsonArray() {
	
	$.ajax({
        url:'${base}/submit/ajax/jsonArray.do',
        contentType : "application/json",
        //data:{"students":arr1},
        data:JSON.stringify(arr1),
        type:'post',
        success:function(msg){
            if(msg=='1'){
                alert('成功');
            }else{
                alert('失败')
            }
        }
    });
};

function jsonString() {
	
	$.ajax({
        url:'${base}/submit/ajax/jsonString.do',
        data:param,
        type:'post',
        success:function(msg){
            if(msg=='1'){
                alert('成功');
            }else{
                alert('失败');
            }
        }
    });
};

function ajaxSubmit() {
	$.ajax({
        url:'${base}/submit/formSubmit.do',
        data:$("#frm").serialize(),
        type:'post',
        success:function(msg){
            if(msg=='1'){
                alert('成功');
            }else{
                alert('失败');
            }
        }
    });
};

$("#uploadFile").change(function(){
	$.ajaxFileUpload({
		url:"${base}/submit/ajaxfileupload.do",
		secureuri:false,
		fileElementId:"uploadFile",//file标签的id
		dataType: "json",
		data:{"fileName":$("#fileName").val()},
		success: function (result,a,b){
			var fileName = result.msg;
			alert(fileName);

		},
		error:function(data,status,e){  
	          alert(e);  
	     } 
	});
});

function ajaxSub(){
	 // 准备好活动资料Options对象  
	var options = {  
	    url:'${base}/submit/ajaxSubmit.do',  
	    type:'post',
	    resetForm :false,
	    clearForm:false,
	    dataType:'json',
	    success: function(res, status, xhr) {
			alert(res.msg)	    	
	    }
	};
	$('#ajaxSubmitFrm').ajaxSubmit(options); 
}

</script>
</body>
</html>